<?php

Class Exchange extends Connect {
    
    static $all = array();
    static $currency = array(
        1 => "Золото",
        2 => "Серебро"
    );
    
    static function getAll(){
        if(count($all) > 0) return true;
        $sql = "SELECT * FROM `".PREFIX_STATIC."exchange` ";
        if( !$result = DBConnect::query($sql, 'exchange')){
            Connect::_error(mysql_error());
            return false;
        }
        while($arr = DBConnect::getOne($result, 'exchange') ){
            Exchange::$all[ ] = array('v' => intval($arr['voices']), 
                                                    '1' => $arr['money1'],
                                                   '2' => $arr['money2'],
                                                   'id' => $arr['id']  );
        }
        return true;
    }
    
    function save($data){
        if( !is_array($data) ) return false;
        $sql = "UPDATE `".PREFIX_STATIC."exchange` SET `voices` = '".$data['vo']."', 
                                                    `money1` = '".$data['au']."',
                                                    `money2` = '".$data['ar']."'
                                                    WHERE `id` = '".$data['id']."'  ";        
        if(!DBConnect::query($sql)){
            $this->_error(mysql_error());
            return false;
        }
        return true;
    }
    
    function add($data){
        if( !is_array($data) ) return false;
        $sql = " INSERT INTO `".PREFIX_STATIC."exchange` (`voices`, `money1`, `money2`)
                                                         VALUES
                                                         ('".$data['vo']."', 
                                                          '".$data['au']."', 
                                                          '".$data['ar']."')";        
        if(!DBConnect::query($sql)){
            $this->_error(mysql_error());
            return false;
        }
        return mysql_insert_id() ;
    }
}
?>
